﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ISingerService
    {
        public bool addSinger(string singerName, string description, string imageURL)
        {
            bool flag = false;
            Singer singer = new Singer();
            try
            {
                long numberSinger = dc.Singers.Count() + 1;
                singer.SingerID = "SINGER" + numberSinger;
                singer.SingerName = singerName;
                singer.Description = description;
                singer.ImageURL = imageURL;
                dc.Singers.InsertOnSubmit(singer);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeSinger(string singerID)
        {
            bool flag = false;
            try
            {
                Singer singer = dc.Singers.Single(s => s.SingerID.Equals(singerID));
                if (singer != null)
                {
                    dc.Singers.DeleteOnSubmit(singer);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateSinger(string singerID, string singerName, string description, string imageURL)
        {
            bool flag = false;
            try
            {
                Singer singer = dc.Singers.Single(s => s.SingerID.Equals(singerID));
                if (singer != null)
                {
                    singer.SingerName = singerName;
                    singer.Description = description;
                    singer.ImageURL = imageURL;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }
        public List<Singer> getAllSinger()
        {
            var list = from s in dc.Singers select s;
            return list.ToList();
        }
        public Singer getSingerByName(string singerName)
        {
            Singer singer = dc.Singers.Single(s => s.SingerName.Equals(singerName));
            return singer;
        }
    }
}